from django.contrib import admin
from django.contrib.auth.models import User

from filmsite.models import Category
from filmsite.models import Video
from filmsite.models import Url
from filmsite.models import Account
from filmsite.models import Comment
from filmsite.models import Problem
from filmsite.models import Search
from filmsite.models import History
from filmsite.models import Follow
from filmsite.models import Message
    
class CategoryAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'pid', 'oid')
    list_display_links = ('id', 'name')
    fields = ('name', 'pid', 'oid')
    ordering = ('id',)
    
class UrlInline(admin.TabularInline):
    model = Url
    extra = 1
    list_display = ('oid', 'video', 'url_type', 'url', 'serial')
    
class VideoAdmin(admin.ModelAdmin):
    list_display = ('title', 'category', 'hits')
    list_filter = ['category']
    search_fields = ['title', 'director', 'actor']
    fieldsets = [
        (None, {'fields':['title']}),
        ('detail', {'fields':['category', 'image', 'director', 'actor', 'content', 'language',
        'area', 'year', 'serial', 'end', 'status', 'update_time', 'intro', 'hits'], 'classes':['collapse']}),
    ]
    list_per_page = 50
    inlines = [UrlInline]
    
class AccountInline(admin.StackedInline):
    model = Account
    can_delete = False
    
class UserAdmin(admin.ModelAdmin):
    list_display = ('username', 'is_staff', 'is_active')
    inlines = [AccountInline]
    
class CommentAdmin(admin.ModelAdmin):
    list_display = ('id', 'video', 'content', 'support', 'against', 'publish_time')
    list_display_links = ('id', 'content')
    search_fields = ['video__title', 'content']
    list_per_page = 100
    
class ProblemAdmin(admin.ModelAdmin):
    list_display = ('id', 'pid', 'user_name', 'problem_type', 'content', 'publish_time', 'reply')
    list_filter = ['reply']
    list_per_page = 50
    
class SearchAdmin(admin.ModelAdmin):
    list_display = ['keywords', 'result', 'search_time']
    list_per_page = 100
    
class HistoryAdmin(admin.ModelAdmin):
    list_display = ['user', 'video', 'url']
    list_per_page = 50
    
class FollowAdmin(admin.ModelAdmin):
    list_display = ['user', 'video']
    list_per_page = 50
    
class MessageAdmin(admin.ModelAdmin):
    list_display = ['user', 'video', 'content']
    list_per_page = 50

# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)

admin.site.register(Category, CategoryAdmin)
admin.site.register(Video, VideoAdmin)
admin.site.register(Comment, CommentAdmin)
admin.site.register(Problem, ProblemAdmin)
admin.site.register(Search, SearchAdmin)
admin.site.register(History, HistoryAdmin)
admin.site.register(Follow, FollowAdmin)
admin.site.register(Message, MessageAdmin)
